<template>
  <div ref="wrapper">
    <slot></slot>
  </div>
</template>

<script>
import BScroll from 'better-scroll'
export default {
  props: {
    probeType: {
      type: Number,
      default: 1
    },
    click: {
      type: Boolean,
      default: true
    },
    data: {
      type: Array,
      default: null
    },
    bounceTime: {
      type: Number,
      default: 500
    }
  },
  mounted () {
    // setTimeout(() => {
    //   this._initScroll()
    // }, 20)
    this.$nextTick(() => {
      this._initScroll()
    })
  },
  methods: {
    _initScroll () {
      if (!this.$refs.wrapper) {
        return false
      }
      this.scroll = new BScroll(this.$refs.wrapper, {
        probeType: this.probeType,
        click: this.click,
        bounceTime: this.bounceTime,
        swipeBounceTime: 350
      })
    },
    enbale () {
      this.scroll && this.scroll.enbale()
    },
    refresh () {
      this.scroll && this.scroll.refresh()
    },
    disable () {
      this.scroll && this.scroll.disable()
    }
  },
  watch: {
    data () {
      setTimeout(() => {
        this.refresh()
      }, 20)
    }
  }
}
</script>

<style lang="stylus">

</style>
